Dart int operator ==
Syntax & Examples
int.operator == operator
The `==` operator in Dart checks if this integer is equal to another value.
Syntax of int.operator ==
The syntax of int.operator == operator is:
operator ==(dynamic other) → boolThis operator == operator of int the equality operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | The value to compare with. |
✐ Examples
1 Comparison of 5 and 3
In this example,
- We assign the values
5and3to the integer variablesnum1andnum2respectively. - We check if
num1is equal tonum2. - We print the result to standard output.
Dart Program
void main() {
int num1 = 5;
int num2 = 3;
bool result = num1 == num2;
print('Result of == operator: $result');
}Output
Result of == operator: false
2 Comparison of 10 and 10
In this example,
- We assign the value
10to both integer variablesnum1andnum2. - We check if
num1is equal tonum2. - We print the result to standard output.
Dart Program
void main() {
int num1 = 10;
int num2 = 10;
bool result = num1 == num2;
print('Result of == operator: $result');
}Output
Result of == operator: true
3 Comparison of -2 and -2
In this example,
- We assign the values
-2to both integer variablesnum1andnum2. - We check if
num1is equal tonum2. - We print the result to standard output.
Dart Program
void main() {
int num1 = -2;
int num2 = -2;
bool result = num1 == num2;
print('Result of == operator: $result');
}Output
Result of == operator: true
Summary
In this Dart tutorial, we learned about operator == operator of int: the syntax and few working examples with output and detailed explanation for each example.